#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using piii = pair<int, pii>;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 2e5 + 5;

int n, m;
int a[N], f[N], ans[N];
vector<int> ch[N];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int u, vector<int>& path) {
  int len = path.size();
  ans[u] = -1;
  per(i, len - 1, 0) {
    int v = path[i];
    if (gcd(a[v], a[u]) != 1) {
      ans[u] = v;
      break;
    }
  }
  path.push_back(u);
  for (int v : ch[u]) {
    dfs(v, path);
  }
  path.pop_back();
}
void change(int u, int val) {
  a[u] = val;
  vector<int> path;
  int p = f[u];
  while (p) {
    path.push_back(p);
    p = f[p];
  }
  reverse(path.begin(), path.end());
  dfs(u, path);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 2, n) {
    int x, y;
    cin >> x >> y;
    ch[x].push_back(y);
    f[y] = x;
  }
  int root = 0;
  rep(i, 1, n) {
    if (f[i] == 0) {
      root = i;
      break;
    }
  }
  vector<int> path;
  dfs(root, path);
  rep(i, 1, m) {
    int op, u;
    cin >> op >> u;
    if (op == 1)
      cout << ans[u] << '\n';
    else {
      int val;
      cin >> val;
      change(u, val);
    }
  }
  return 0;
}